package a;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

public class J extends Application{

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		FlowPane pane = new FlowPane();
		pane.setPrefSize(320, 502);
		pane.setStyle("-fx-background-color:#eee");
		
		TextField textField = new TextField();
		textField.setPrefSize(320, 120);
		textField.setText("0");
		textField.setFont(Font.font(null, FontWeight.BOLD, 40));
		textField.setAlignment(Pos.CENTER_RIGHT);
		textField.setEditable(false);
//		textField.setDisable(false);  不知道这是啥
//		textField.setStyle("-fx-border-color:#eee"); //没用
		textField.setFocusTraversable(false);
		textField.setStyle("-fx-background-color:#eee"); /*与文本框相同的背景色 这里设置它是因为想要得到 简洁的效果
		取消边框*/
		
		pane.getChildren().add(textField);
		
		GridPane g = new GridPane();
		g.setHgap(5);
		g.setPrefSize(320, 30);
//		g.setStyle("-fx-background-color:red");
		
		Button mc = new Button("MC");
		mc.setPrefSize(50, 30);
		mc.setStyle("-fx-background-color:#eee");
		mc.setOnAction(e->{
			String str1 = mc.getText();
			if(str1.equals("MC")) {
				textField.setText("MC");
			}
			
		});

		Button mr = new Button("MR");
		mr.setPrefSize(50, 30);
		mr.setStyle("-fx-background-color:#eee");
		mr.setOnMouseEntered(e->{//鼠标经过
			mr.setCursor(Cursor.HAND);//变成手
			mr.setStyle("-fx-background-color:blue");
			mr.setTextFill(Color.WHITE);
		});
		mr.setOnMouseExited(e->{//鼠标离开
			mr.setStyle("-fx-background-color:#eee");
			mr.setTextFill(Color.BLACK);
		});
		
		
		Button m0 = new Button("M+");
		m0.setPrefSize(50, 30);
		m0.setStyle("-fx-background-color:#eee");
		
		Button m1 = new Button("M-");
		m1.setPrefSize(50, 30);
		m1.setStyle("-fx-background-color:#eee");
		
		Button ms = new Button("MS");
		ms.setPrefSize(50, 30);
		ms.setStyle("-fx-background-color:#eee");
		
		Button m = new Button("M");
		m.setPrefSize(50, 30);
		m.setStyle("-fx-background-color:#eee");
		
		g.add(mc, 0, 0);
		g.add(mr, 1, 0);
		g.add(m0, 2, 0);
		g.add(m1, 3, 0);
		g.add(ms, 4, 0);
		g.add(m, 5, 0);
		
		pane.getChildren().add(g);
		
		FlowPane fp = new FlowPane();
		fp.setPrefSize(320,352 );
		fp.setHgap(1);
		fp.setVgap(1);
		
		Button bfh = new Button("%");
		bfh.setPrefSize(79, 50);
		bfh.setFocusTraversable(false);
		bfh.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button gh = new Button("√");
		gh.setPrefSize(79, 50);
		gh.setFocusTraversable(false);
		gh.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button pf = new Button("x²");
		pf.setPrefSize(79, 50);
		pf.setFocusTraversable(false);
		pf.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button ds = new Button("1/x");
		ds.setPrefSize(79, 50);
		ds.setFocusTraversable(false);
		ds.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		
		Button ce = new Button("CE");
		ce.setPrefSize(79, 50);
		ce.setFocusTraversable(false);
		ce.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button c = new Button("C");
		c.setPrefSize(79, 50);
		c.setFocusTraversable(false);
		c.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button sc = new Button("<-");
		sc.setPrefSize(79, 50);
		sc.setFocusTraversable(false);
		sc.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button cf = new Button("÷");
		cf.setPrefSize(79, 50);
		cf.setFocusTraversable(false);
		cf.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		cf.setOnMouseEntered(e->{//鼠标经过
			cf.setCursor(Cursor.HAND);//变成手
			cf.setStyle("-fx-background-color:#11f");
			cf.setTextFill(Color.WHITE);
		});
		cf.setOnMouseExited(e->{//鼠标离开
			cf.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
			cf.setDefaultButton(true);
			cf.setTextFill(Color.BLACK);
		});
		
		Button qi = new Button("7");
		qi.setPrefSize(79, 50);
		qi.setFocusTraversable(false);
		qi.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button ba = new Button("8");
		ba.setPrefSize(79, 50);
		ba.setFocusTraversable(false);
		ba.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button jiu = new Button("9");
		jiu.setPrefSize(79, 50);
		jiu.setFocusTraversable(false);
		jiu.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button chen = new Button("×");
		chen.setPrefSize(79, 50);
		chen.setFocusTraversable(false);
		chen.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		
		chen.setOnMouseEntered(e->{//鼠标经过
			chen.setCursor(Cursor.HAND);//变成手
			chen.setStyle("-fx-background-color:#11f");
			chen.setTextFill(Color.WHITE);
		});
		chen.setOnMouseExited(e->{//鼠标离开
			chen.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
			chen.setTextFill(Color.BLACK);
		});
		
		Button si = new Button("4");
		si.setPrefSize(79, 50);
		si.setFocusTraversable(false);
		si.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button wu = new Button("5");
		wu.setPrefSize(79, 50);
		wu.setFocusTraversable(false);
		wu.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button liu = new Button("6");
		liu.setPrefSize(79, 50);
		liu.setFocusTraversable(false);
		liu.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button jia = new Button("+");
		jia.setPrefSize(79, 50);
		jia.setFocusTraversable(false);
		jia.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		
		jia.setOnMouseEntered(e->{//鼠标经过
			jia.setCursor(Cursor.HAND);//变成手
			jia.setStyle("-fx-background-color:#11f");
			jia.setTextFill(Color.WHITE);
		});
		jia.setOnMouseExited(e->{//鼠标离开
			jia.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
			jia.setTextFill(Color.BLACK);
		});
		
		Button yi = new Button("1");
		yi.setPrefSize(79, 50);
		yi.setFocusTraversable(false);
		yi.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button er = new Button("2");
		er.setPrefSize(79, 50);
		er.setFocusTraversable(false);
		er.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button san = new Button("3");
		san.setPrefSize(79, 50);
		san.setFocusTraversable(false);
		san.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button jian = new Button("-");
		jian.setPrefSize(79, 50);
		jian.setFocusTraversable(false);
		jian.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		
		jian.setOnMouseEntered(e->{//鼠标经过
			jian.setCursor(Cursor.HAND);//变成手
			jian.setStyle("-fx-background-color:#11f");
			jian.setTextFill(Color.WHITE);
		});
		jian.setOnMouseExited(e->{//鼠标离开
			jian.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
			jian.setTextFill(Color.BLACK);
		});
		
		Button zf = new Button("±");
		zf.setPrefSize(79, 50);
		zf.setFocusTraversable(false);
		zf.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button lin = new Button("0");
		lin.setPrefSize(79, 50);
		lin.setFocusTraversable(false);
		lin.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button dian = new Button(".");
		dian.setPrefSize(79, 50);
		dian.setFocusTraversable(false);
		dian.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		Button den = new Button("=");
		den.setPrefSize(79, 50);
		den.setFocusTraversable(false);
		den.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
		
		den.setOnMouseEntered(e->{//鼠标经过
			den.setCursor(Cursor.HAND);//变成手
			den.setStyle("-fx-background-color:#11f");
			den.setTextFill(Color.WHITE);
		});
		den.setOnMouseExited(e->{//鼠标离开
			den.setStyle("-fx-background-color:#ddd;-fx-border-color:#eee");
			den.setTextFill(Color.BLACK);
		});
		
		fp.getChildren().addAll(bfh,gh,pf,ds,ce,c,sc,cf,qi,ba,jiu,chen,si,wu,liu,jia,yi,er,san,jian,zf,lin,dian,den);
		
//		fp.setStyle("-fx-background-color:red");
		
		pane.getChildren().add(fp);
		
		Scene scene = new Scene(pane);

		primaryStage.setWidth(320);
		primaryStage.setHeight(502);
		primaryStage.setResizable(false);//窗口大小不可变 ---如果不设置上面两行代码，控件会错位
		primaryStage.setTitle("计算器");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		Application.launch(args);
	}
}
